package com.baway.biliclitent.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.view.ViewGroup;

import java.util.ArrayList;

/**
 * Created by hcc on 16/8/4 14:12
 * 100332338@qq.com
 * <p/>
 * 主界面Fragment模块Adapter
 */
public class HomePagerAdapter extends FragmentPagerAdapter {

  private ArrayList<Fragment> fragments = new ArrayList<>();
  private String[] titles;

  public HomePagerAdapter(FragmentManager fm, ArrayList<Fragment> fragments, String[] titles) {
    super(fm);
    this.fragments = fragments;
    this.titles = titles;
  }

  @Override
  public int getCount() {
    return fragments.size();
  }

  @Override
  public CharSequence getPageTitle(int position) {
    return titles[position];
  }

  @Override
  public Fragment getItem(int position) {
    return fragments.get(position);
  }

  @Override
  public void destroyItem(ViewGroup container, int position, Object object) {
    // 覆写destroyItem并且空实现,这样每个Fragment中的视图就不会被销毁
    // super.destroyItem(container, position, object);
  }

  @Override
  public int getItemPosition(Object object) {
    return PagerAdapter.POSITION_NONE;
  }
}
